package internal

import (
	"context"
	"go-canal/internal/dao"
	"gorm.io/gorm"
)

type CanalAnalysisServer interface {
	// InsertMessage UpdateMessage DeleteMessage dml
	InsertMessage(ctx context.Context, table string, data ...map[string]interface{}) error
	UpdateMessage(ctx context.Context, table string, data ...map[string]interface{}) error
	DeleteMessage(ctx context.Context, table string, data ...map[string]interface{}) error

	// AlterTable ddl
	//AlterTable()

	// 防止被其他结构体实现
	s()
}

type canalAnalysisServer struct {
	ormDao dao.AnalysisDao
	ddlDao dao.AnalysisDDLDao
}

func NewCanalAnalysisServer(db *gorm.DB) CanalAnalysisServer {
	return &canalAnalysisServer{
		ormDao: dao.NewDao(db),
		ddlDao: dao.NewDDLDao(db),
	}
}

func (s *canalAnalysisServer) s() {
	return
}

func (s *canalAnalysisServer) InsertMessage(ctx context.Context, table string, data ...map[string]interface{}) error {
	return s.ormDao.InsertMessage(ctx, table, data...)
}

func (s *canalAnalysisServer) UpdateMessage(ctx context.Context, table string, data ...map[string]interface{}) error {
	return s.ormDao.UpdateMessage(ctx, table, data...)
}

func (s *canalAnalysisServer) DeleteMessage(ctx context.Context, table string, data ...map[string]interface{}) error {
	return s.ormDao.DeleteMessage(ctx, table, data...)
}
